package com.icms.person;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.icms.core.base.BaseDaoAbs;
import com.icms.core.hibernate.IHibernteDao;



@Service @Transactional
public class PersonService extends BaseDaoAbs<Person> implements IPersonService {

	@Autowired
	private ITreeService tree ;
	
	@Autowired
	private IHibernteDao<Tree> basedaoTree ;
	
	@Override
	public void add() {
		String sql = "insert into person(name) value(?)" ;
		Object[] obj = new Object[]{"jt33"} ;
		this.getJt().update(sql, obj) ;

		String sql2 = "insert into person(name) value(?)" ;
		Object[] obj2 = new Object[]{"jt44"} ;
		this.getJt().update(sql2, obj2) ;
	}

	@Override
	public void add2() {
		Person p = new Person() ;
		p.setName("aa") ;
		p.setSex("男") ;
		this.getHibernate().add(p) ;
		//int i=1/0;
		Tree t = new Tree() ;
		t.setName("hello") ;
		this.basedaoTree.add(t) ;
		
		//this.tree.add() ;
	}

	@Override
	@Cacheable(value="serviceCache", key="#id")
	public Person get(String id) {
		return (Person) this.getHibernate().getCurrentSession().get(Person.class, id) ;
	}
	
	@Override
	@Cacheable(value="serviceCache")
	public List<Person> findAll() {
		List<Person> list = this.getHibernate().list("select t from Person t") ;
		return list;
	}

	@Override
	@Cacheable(value="serviceCache")
	public List<Person> findAllSQL() {
		List<Person> listSQL = this.getHibernate().listSQL("select t.* from t_person t", Person.class, false) ;
		return listSQL;
	}
	

}
